<?php

include_once 'Expression.php';

/**
 * Represents a reference to a method.
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/MethodReferenceExpressionExample.php 
 */

class MethodReferenceExpression extends Expression
{
    /**
     * The MethodReferenceExpression constructor
     * @param string $MethodName The name of the method to reference
     * @param Expression $TargetObject The object that the method belongs to
     */
    
    public function __construct($MethodName, Expression $TargetObject)
    {
        parent::__construct();
        
        $this->set_MethodName($MethodName);
        $this->set_TargetObject($TargetObject);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'MethodName')
        {
            $this->set_MethodName($value);
        }
        
        if($name == 'TargetObject')
        {
            $this->set_TargetObject($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'MethodName')
        {
            return $this->get_MethodName();
        }
        
        if($name == 'TargetObject')
        {
            return $this->get_TargetObject();
        }
    }
    
    /**
     * The $MethodName getter method
     * @return string 
     */
    
    public function get_MethodName()
    {
        return $this->MethodName;
    }
    
    /**
     * The $MethodName setter method
     * @param type $MethodName
     * @throws InvalidArgumentException 
     * 
     * @assert (123) throws InvalidArgumentException
     * @assert (true) throws InvalidArgumentException
     */

    public function set_MethodName($MethodName)
    {
        if(is_string($MethodName))
        {
            $this->MethodName = $MethodName;
        }
        else
        {
            throw new InvalidArgumentException(
                'The method name must be a string.');
        }
    }

    /**
     * The $TargetObject getter method
     * @return Expression 
     */
    
    public function get_TargetObject()
    {
        return $this->TargetObject;
    }
    
    /**
     * The $TargetObject setter method
     * @param Expression $TargetObject 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     */

    public function set_TargetObject(Expression $TargetObject)
    {
        $this->TargetObject = $TargetObject;
    }

    /**
     * The name of the method to reference
     * @var string 
     */
    
    private $MethodName;
    
    /**
     * The object that the method belongs to
     * @var Expression 
     */
    
    private $TargetObject;
}

?>
